<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	template="/layout/layout_nav_footer_adm.xhtml">
	<ui:define name="titre">
		<p:graphicImage value="/img/administration.png" />
	</ui:define>
	<ui:define name="content">
		
			<fieldset id="fieldset">
			    <legend id="fieldset2">Gestion des recettes</legend>
			    
			    
			    <h:form styleClass="form-horizontal" rendered="#{loginbean.adminLogged == true}" id="all_recipe">
			    <div class="span3 well" >
				    <p:dataTable style="text-align:center" var="recipe" value="#{recipemanagerbean.recipeList}" rowStyleClass="#{recipemanagerbean.currentRecipe.id == recipe.id ? 'rowSelected' : null}"
				    			 paginator="true" rows="7" paginatorTemplate="{PreviousPageLink} {PageLinks} {NextPageLink}">
				    	<p:column headerText="Titre">
				    		<h:outputText value="#{recipe.title}" />
				    	</p:column>
				    	<p:column>
				    		<p:commandButton id="select_button" icon="ui-icon-search" title="View" update=":current_recipe :all_recipe">
				    			<f:setPropertyActionListener value="#{recipe}" target="#{recipemanagerbean.currentRecipe}" />
				    		</p:commandButton>
				    	</p:column>
				    		
				    </p:dataTable>
				    <div style="width:30%; margin:auto;">
				    <h:commandButton style="width:100%; margin-top:5%;" id="add_button" value="Ajouter" styleClass="btn btn-primary" update=":current_recipe" >
				    	<f:setPropertyActionListener value="#{null}" target="#{recipemanagerbean.currentRecipe}" />
				    </h:commandButton>
			    	</div>
			    </div>
			    </h:form>
			    
		
			    
				<h:form styleClass="form-horizontal" rendered="#{loginbean.adminLogged == true}" id="current_recipe" autoUpdate="true">
			    <div class="span7 well"  id="current_recipe">
			    
			    		<div class="control-group">
					    	<h:outputLabel styleClass="control-label" for="title" value="Titre :" style="margin-left:32px"/>
					    	<div class="controls">
					      		<h:inputText id="title" value="#{recipemanagerbean.currentRecipe.title}" requiredMessage="Title required" required="true">
					      			<f:ajax event="blur" render="messageTitle" />
					      		</h:inputText>
					      		<p:message id="messageTitle" for="title" />
						    </div>
			    		</div>
			    		<div class="control-group">
					    	<p:graphicImage styleClass="pull-left" value="#{searchRecipe.imgPreparationDuration}" />
			    			<h:outputLabel styleClass="control-label pull-left" for="duration" value="Temps de préparation :"/>  
					    	<div class="controls">
					      		<p:spinner id="duration" value="#{recipemanagerbean.currentRecipe.preparationDuration}" min="1" max="1000">
					      			<f:ajax event="blur" render="messageDuration" />
					      		</p:spinner>
					      		<p:message id="messageDuration" for="duration" />
						    </div>
						    
			    		</div>
			    		<div class="control-group">
					    	<p:graphicImage styleClass="pull-left" value="#{searchRecipe.imgCookExpertise}" />
			    			<h:outputLabel styleClass="control-label" for="expertise" value="Niveau de cuisine :" />  
					    	<div class="controls">
					      		<p:rating id="expertise" value="#{recipemanagerbean.currentRecipe.cookExpertise}" stars="5" style="position:relative;top:8px" />
					      		<p:message id="messageExpertise" for="expertise" />
						    </div>
			    		</div>
			    		<div class="control-group">
			    			<p:graphicImage styleClass="pull-left" value="#{searchRecipe.imgNbOfPerson}" />
				        	<h:outputLabel for="nbOfPerson" styleClass="control-label" value="Nb de personne :" />  
					    	<div class="controls">
					      		<h:outputText id="output" value="#{recipemanagerbean.currentRecipe.nbPersons} personnes"/>  
						       	<h:inputHidden id="nbOfPerson" value="#{recipemanagerbean.currentRecipe.nbPersons}" required="true" /> 
						       	<p:slider for="nbOfPerson" display="output" minValue="1" maxValue="10" style="width:200px;margin-left:20px" displayTemplate="{value} personnes">
						       		<f:ajax event="slideEnd" render="messageNbOfPerson" />
						       	</p:slider>
						       	<p:message id="messageNbOfPerson" for="nbOfPerson" />
						    </div>
			    		</div>
			    		<div class="control-group">
					    	<p:graphicImage styleClass="pull-left" value="#{searchRecipe.imgCookType}" />
			    			<h:outputLabel styleClass="control-label" for="type" value="Type de recette :"/>
					    	<div class="controls">
				    			 <p:selectOneMenu value="#{recipemanagerbean.currentRecipe.cookType}" id="type" required="true" requiredMessage="Cook type required">
							    	<f:selectItem itemLabel="--" itemValue="" />
							    	<c:forEach var="ct" items="#{recipemanagerbean.cookTypes}">
							    		<f:selectItem itemLabel="#{ct}" itemValue="#{ct}" />
							    		<h:outputText value="#{ct}" />
							    	</c:forEach>
							    	<f:ajax event="blur" render="messageType" />
				        		</p:selectOneMenu>
				        		<p:message id="messageType" for="type" />
		        			</div>
			    		</div>
			    		<div class="control-group">
			    			<div class="controls">
					    		<p:inputTextarea id="description" required="true" requiredMessage="Description required" value="#{recipemanagerbean.currentRecipe.description}" rows="10" cols="80" counter="counter" maxlength="500"       
		   						 counterTemplate="Encore {0} caractères" autoResize="false" style="margin-left:24px;">
		   						 	<f:ajax event="blur" render="messageType" />
		   						 </p:inputTextarea>
		   						 <h:outputText id="counter" /> 
		   						 <p:message id="messageDescription" for="description" /> 
	   						 </div>
   						 </div>
   						 <div class="control-group">
		    				<div class="controls">
		    					<h:commandButton style="margin-right:10%;" id="buttonSave" value="Save" type="submit" styleClass="btn btn-primary" update=":all_recipe" action="#{recipemanagerbean.saveRecipe}" actionListener="#{recipemanagerbean.attrListener}" />
		    					<h:commandButton id="buttonDelete" value="Delete" type="submit" styleClass="btn btn-primary" update=":current_recipe :all_recipe" action="#{recipemanagerbean.delete}" actionListener="#{recipemanagerbean.attrListener}" />
		    					<p:message id="messageButtonDelete" for="buttonDelete" errorStyle="color:red" infoStyle="color:green" style="margin-top:10px" />
		    					<p:message id="messageButtonSave" for="buttonSave" errorStyle="color:red" infoStyle="color:green" style="margin-top:10px" />
		    				</div>
		    			</div>
			   	</div>
			   	</h:form> 
			</fieldset>
		
	</ui:define>
</ui:composition>